package unitest.Suite.tests
{
	import com.flashshe.ds.linear.IStack;
	import com.flashshe.ds.linear.VectorStack;
	import flexunit.framework.Assert;

	public class TestStack
	{		
		private var stack:IStack;
		
		[Before]
		public function setUp():void
		{
			stack = new VectorStack();			
			stack.push("a");
			stack.push("b");
		}		
		
		[Test]
		public function pushElements():void
		{			
			Assert.assertTrue(stack.contains("a"));
			Assert.assertTrue(stack.contains("b"));
		}
		
		[Test]
		public function popElements():void
		{
			stack.pop();
			Assert.assertTrue(stack.contains("a"));
			Assert.assertFalse(stack.contains("b"));
			stack.pop();
			Assert.assertFalse(stack.contains("a"));
		}
		
		[Test]
		public function getPopElement():void
		{
			Assert.assertEquals("b", stack.pop());
			Assert.assertEquals("a", stack.pop());
		}
		
		[Test]
		public function peek():void
		{
			stack.clear();
			Assert.assertNull(stack.peek());
			stack.push("a");
			Assert.assertEquals("a", stack.peek());
			stack.push("b");
			Assert.assertEquals("b", stack.peek());
		}
		
		[Test]
		public function size():void
		{
			stack.clear();
			Assert.assertEquals(0, stack.size);			
			stack.push("a");			
			stack.push("b");
			Assert.assertEquals(2, stack.size);	
			stack.pop();		
			Assert.assertEquals(1, stack.size);
		}
		
		[Test]
		public function isEmpty():void
		{
			stack.clear();
			Assert.assertTrue(stack.isEmpty());				
			stack.push("a");			
			Assert.assertFalse(stack.isEmpty());		
		}
		
		[Test]
		public function clear():void
		{
			Assert.assertFalse(stack.isEmpty());
			stack.push("c");
			stack.clear();
			Assert.assertTrue(stack.isEmpty());						
		}
		
		[Test]
		public function contains():void
		{
			stack.push("c");
			Assert.assertTrue(stack.contains("c"));		
			stack.pop();
			Assert.assertFalse(stack.contains("c"));		
		}
		
		[Test]
		public function addElements():void
		{			
			stack.add("c");
			stack.add("d");
			Assert.assertTrue(stack.contains("c"));
			Assert.assertTrue(stack.contains("d"));
		}
		
		[Test]
		public function removeElements():void
		{
			stack.remove();
			Assert.assertTrue(stack.contains("a"));
			Assert.assertFalse(stack.contains("b"));
			stack.remove();
			Assert.assertFalse(stack.contains("a"));
		}
		
		[Test]
		public function getRemovedElement():void
		{
			Assert.assertEquals("b", stack.remove());
			Assert.assertEquals("a", stack.remove());
		}
		
		[Test]
		public function getValue():void
		{
			stack.clear();
			Assert.assertNull(stack.getValue());
			stack.push("a");
			Assert.assertEquals("a", stack.getValue());
			stack.push("b");
			Assert.assertEquals("b", stack.getValue());
		}
	}
}